﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{

    public class DrawingPileRebarStructure
    {

        #region 桩基钢筋构造图纸
        EPileType ePCType;
        eDB N1, N2, N3, N4, N5, N6, N7;
        int numN1, numN2, numN3;
        int spaceN4, spaceN5, spaceN6;
        double Length;      // 总桩长，从cut off level，mm为单位
        int Cover = 75;

        int DiaPile = 1000; // 桩径

        int LapLength = 300;    // 搭接长度
        int ringSpace = 2000;   // 加强筋间距

        int FirstTieLen = 6500; // 第一段6.5m加密区域
        int SecTieLen = 8000;   // 第二段8m加密区域
        double DowelLen = 1200;

        //声明与内加强筋有关的参数变量
        int PhiTop, PhiMitUp, PhiMitLo, PhiBot; //外径
        public void DrawingPile(Database db, Point3d startPoint, EPileType _ePCType, double pileLength, int dia, int dowel, RebarCollection RebarList, string _dwgPath, int pageNo = 0, int divNo = 0)
        {
            #region 基础数据配置 ，对应桩基算量计算
            Length = pileLength;
            ePCType = _ePCType;
            DowelLen = dowel;
            DiaPile = dia;
            if (dia == 1000)
            {
                switch (ePCType)
                {
                    case EPileType.None:
                        return;
                    case EPileType.Type1:
                        N1 = eDB.DB20;
                        numN1 = 20;
                        N2 = eDB.DB20;
                        numN2 = 10;
                        N3 = eDB.DB20;
                        numN3 = 8;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB16;
                        spaceN4 = 200;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type2:
                        N1 = eDB.DB20;
                        numN1 = 20;
                        N2 = eDB.DB20;
                        numN2 = 14;
                        N3 = eDB.DB20;
                        numN3 = 8;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB16;
                        spaceN4 = 200;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type3:
                        N1 = eDB.DB25;
                        numN1 = 20;
                        N2 = eDB.DB20;
                        numN2 = 16;
                        N3 = eDB.DB20;
                        numN3 = 10;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB20;
                        spaceN4 = 150;
                        spaceN5 = 250;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type4:
                        N1 = eDB.DB28;
                        numN1 = 26;
                        N2 = eDB.DB25;
                        numN2 = 16;
                        N3 = eDB.DB20;
                        numN3 = 10;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB20;
                        spaceN4 = 150;
                        spaceN5 = 250;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type5:
                        N1 = eDB.DB32;
                        numN1 = 30;
                        N2 = eDB.DB25;
                        numN2 = 24;
                        N3 = eDB.DB20;
                        numN3 = 14;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 250;
                        spaceN6 = 500;
                        break;
                    case EPileType.Type6:
                        N1 = eDB.DB32;
                        numN1 = 36;
                        N2 = eDB.DB25;
                        numN2 = 24;
                        N3 = eDB.DB20;
                        numN3 = 14;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 250;
                        spaceN6 = 500;
                        break;
                    case EPileType.Type7:
                        N1 = eDB.DB32;
                        numN1 = 40;
                        N2 = eDB.DB25;
                        numN2 = 28;
                        N3 = eDB.DB20;
                        numN3 = 14;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 250;
                        spaceN6 = 500;
                        break;
                    case EPileType.Type1T:
                        N1 = eDB.DB25;
                        numN1 = 28;
                        N2 = eDB.DB25;
                        numN2 = 28;
                        N3 = eDB.DB20;
                        numN3 = 28;
                        N4 = eDB.DB16;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 250;
                        spaceN6 = 500;                      
                        break;
                }
            }
            else
            {
                switch (ePCType)
                {
                    case EPileType.None:
                        return;
                    case EPileType.Type1:
                        N1 = eDB.DB20;
                        numN1 = 13;
                        N2 = eDB.DB16;
                        numN2 = 10;
                        N3 = eDB.DB16;
                        numN3 = 8;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB16;
                        spaceN4 = 200;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type2:
                        N1 = eDB.DB25;
                        numN1 = 10;
                        N2 = eDB.DB20;
                        numN2 = 10;
                        N3 = eDB.DB16;
                        numN3 = 8;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB20;
                        spaceN4 = 200;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type3:
                        N1 = eDB.DB25;
                        numN1 = 16;
                        N2 = eDB.DB20;
                        numN2 = 16;
                        N3 = eDB.DB16;
                        numN3 = 12;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB20;
                        spaceN4 = 200;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type4:
                        N1 = eDB.DB32;
                        numN1 = 18;
                        N2 = eDB.DB25;
                        numN2 = 18;
                        N3 = eDB.DB20;
                        numN3 = 12;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        SecTieLen = (int)(Length * 1000) / 3 - FirstTieLen;
                        break;
                    case EPileType.Type5:
                        N1 = eDB.DB32;
                        numN1 = 28;
                        N2 = eDB.DB25;
                        numN2 = 22;
                        N3 = eDB.DB20;
                        numN3 = 12;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        break;
                    case EPileType.Type6:
                        N1 = eDB.DB32;
                        numN1 = 34;
                        N2 = eDB.DB25;
                        numN2 = 26;
                        N3 = eDB.DB20;
                        numN3 = 14;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        break;
                    case EPileType.Type7:
                        N1 = eDB.DB32;
                        numN1 = 40;
                        N2 = eDB.DB25;
                        numN2 = 30;
                        N3 = eDB.DB20;
                        numN3 = 14;
                        N4 = eDB.DB12;
                        N5 = eDB.DB12;
                        N6 = eDB.DB12;
                        N7 = eDB.DB25;
                        spaceN4 = 150;
                        spaceN5 = 300;
                        spaceN6 = 500;
                        break;
                }
            }
            #endregion


            PhiTop = DiaPile - 2 * Cover - 2 * Convert.ToInt32(N1) - 2 * Convert.ToInt32(N4);   //对应7a
            PhiMitUp = DiaPile - 2 * Cover - 2 * Convert.ToInt32(N1) - 2 * Convert.ToInt32(N5); //对应7b
            PhiMitLo = DiaPile - 2 * Cover - 2 * Convert.ToInt32(N2) - 2 * Convert.ToInt32(N5); //对应7c
            PhiBot = DiaPile - 2 * Cover - 2 * Convert.ToInt32(N3) - 2 * Convert.ToInt32(N6);   //对应7d

            #region 绘制出图
            Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            DrawingRebarPileStructure(db, ref ext, startPoint.Convert3D(-60), _dwgPath, RebarList);
            DrawSection(db, ref ext, startPoint.Convert2D(0,-10), RebarList);
            DrawingPileStructure(db, ref ext, startPoint.Convert3D(185,75), _dwgPath, RebarList);
            DrawingNote(db, ref ext, startPoint.Convert3D(180,-45), _dwgPath);
            #endregion

            Common.CreateLayoutNew(db, "桩基钢筋", ext, 1, 2, pageNo, divNo, false);
        }
      

        public void DrawingRebarPileStructure(Database db, ref Extents2d ext, Point3d startPoint, string _dwgPath, RebarCollection RebarList)
        {
            //Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            double scale = 1;
            Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicV = new Dictionary<string, string>();
            string _blcName = "TYPEB3C";
            Point3d blockPt = startPoint;
            int mainLen = 12000;   // 主筋长度,12m
           
            //db.CopyBlockFromFile(_dwgPath, _blcName);
            //BlockTool.InsertBlockReference(blockPt.Convert3D(0, -5), scale, _blcName, _dwgPath, null, null, ref ext);
            double N2CAP = GlobalFuncs.transmit10Num(GlobalFuncs.GetLapLength(FDEE.Model.eConcreteClass.C30, N2) * 1.7 / 1.3) * 0.001;
            double N3CAP = GlobalFuncs.transmit10Num(GlobalFuncs.GetLapLength(FDEE.Model.eConcreteClass.C30, N3) * 1.7 / 1.3) * 0.001;
            int Len2b = SecTieLen + FirstTieLen + (int)DowelLen - mainLen + (int)(N2CAP * 1000);
            List<RebarBase> rebMainN3C = RebarList.FindAll(t => (t.MBarMark == 3&&t.CBarMark=="c"));
            if (numN1 == numN2)
            {
                if (numN2 == numN3)
                {
                    if (rebMainN3C.Count > 0)
                        _blcName = "TYPE13-C";
                    else
                        _blcName = "TYPE13-B";
                }
                else
                {
                    if (Len2b > 12 * 1000)
                    {
                        if (rebMainN3C.Count > 0)
                            _blcName = "TYPE12C3C";
                        else
                            _blcName = "TYPE12C3B";
                    }
                    else
                    {
                        if (rebMainN3C.Count > 0)
                            _blcName = "TYPE13C";
                        else
                            _blcName = "TYPE13B";
                    }
                }
            }
            else
            {
                if (Len2b > 12 * 1000)
                {
                    if (rebMainN3C.Count > 0)
                        _blcName = "TYPEB2C3C";
                    else
                        _blcName = "TYPEB2C3B";
                }
                else
                {
                    if (rebMainN3C.Count > 0)
                        _blcName = "TYPEB3C";
                    else
                        _blcName = "TYPEB3B";
                }
            }
            string strDia = "Φ" + ((DiaPile - 2 * Cover) * 0.001).ToString("0.000") + " (OD)";
            dic = new Dictionary<string, Dictionary<string, string>>();
            dicV = new Dictionary<string, string>();
            dicV.Add((SecTieLen * 0.001).ToString("0.000"), "string");
            dic.Add("MIDLEN", dicV);
            dicV = new Dictionary<string, string>();
            dicV.Add(N2CAP.ToString("0.000"), "string");
            dic.Add("N2CAP", dicV);
            dicV = new Dictionary<string, string>();
            dicV.Add(N3CAP.ToString("0.000"), "string");
            dic.Add("N3CAP", dicV);
      
                dicV = new Dictionary<string, string>();
                dicV.Add((DiaPile*0.001).ToString("0.000"), "string");
                dic.Add("DIA", dicV);
                dicV = new Dictionary<string, string>();
                dicV.Add(((DiaPile - 2 * Cover) * 0.001).ToString("0.000"), "string");
                dic.Add("DIAS", dicV);
            
            List<RebarBase> rebMainN = RebarList.FindAll(t => (t.MBarMark == 1));
            string txtMainN = "";
            for (int i = 0; i < rebMainN.Count; i++)
            {
                string value;
                if (rebMainN[i].SBarMark != 0)
                    value = rebMainN[i].MBarMark.ToString() + "." + rebMainN[i].SBarMark.ToString() + rebMainN[i].CBarMark;
                else
                    value = rebMainN[i].MBarMark.ToString() + rebMainN[i].CBarMark;
                if (rebMainN[i].CBarMark == "a")
                {
                    txtMainN = value + " -" + (numN3) + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N11A", dicV);
                    txtMainN = value + " -" + (rebMainN[i].Quantity - numN3) + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N12A", dicV);
                }
                else if (rebMainN[i].CBarMark == "b")
                {
                    txtMainN = value + "  -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N1B", dicV);
                    string val = rebMainN[i].Length.ToString("0.000");
                    dicV = new Dictionary<string, string>();
                    dicV.Add(val, "string");
                    dic.Add("LENN1", dicV);

                }
                else
                {
                    txtMainN = " " + value + "  -" + (numN3) + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N11A", dicV);
                    txtMainN = " " + value + "  -" + (rebMainN[i].Quantity - numN3) + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N12A", dicV);
                }
            }

            rebMainN = RebarList.FindAll(t => (t.MBarMark == 2));
            for (int i = 0; i < rebMainN.Count; i++)
            {
                string value;
                if (rebMainN[i].SBarMark != 0)
                    value = rebMainN[i].MBarMark.ToString() + "." + rebMainN[i].SBarMark.ToString() + rebMainN[i].CBarMark;
                else
                    value = rebMainN[i].MBarMark.ToString() + rebMainN[i].CBarMark;
                if (rebMainN[i].CBarMark == "a")
                {
                    txtMainN = value + " -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N2A", dicV);
                }
                else if (rebMainN[i].CBarMark == "b")
                {
                    txtMainN = value + " -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N2B", dicV);
                    if (Len2b <= 12 * 1000)
                    {
                        string val = rebMainN[i].Length.ToString("0.000");
                        dicV = new Dictionary<string, string>();
                        dicV.Add(val, "string");
                        dic.Add("LENN2", dicV);
                    }
                }
                else if (rebMainN[i].CBarMark == "c")
                {
                    txtMainN = value + " -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N2C", dicV);

                    string val = rebMainN[i].Length.ToString("0.000");
                    dicV = new Dictionary<string, string>();
                    dicV.Add(val, "string");
                    dic.Add("LENN2", dicV);
                }
            }
            rebMainN = RebarList.FindAll(t => (t.MBarMark == 3));
            for (int i = 0; i < rebMainN.Count; i++)
            {
                string value;
                if (rebMainN[i].SBarMark != 0)
                    value = rebMainN[i].MBarMark.ToString() + "." + rebMainN[i].SBarMark.ToString() + rebMainN[i].CBarMark;
                else
                    value = rebMainN[i].MBarMark.ToString() + rebMainN[i].CBarMark;
                if (rebMainN[i].CBarMark == "a")
                {
                    txtMainN = value + " -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N3A", dicV);
                }
                else if (rebMainN[i].CBarMark == "b")
                {
                    txtMainN = value + " -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    if (rebMainN[i].SBarMark>0)
                    {
                        TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(120.8, 41+3.6*(rebMainN[i].SBarMark-1)), txtMainN, GeTools.DegreeToRadian(0), 5,0.6);
                    }
                    else
                    {
                        if (_blcName.Contains("3C"))
                            TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(120.8, 42), txtMainN, GeTools.DegreeToRadian(0));
                        else
                        {
                            dicV = new Dictionary<string, string>();
                            dicV.Add(txtMainN, "string");
                            dic.Add("N3B", dicV);
                        }
                    }  
                    if(rebMainN.Count==2)
                    {
                        string val = rebMainN[i].Length.ToString("0.000");
                        dicV = new Dictionary<string, string>();
                        dicV.Add(val, "string");
                        dic.Add("LENN3", dicV);
                    }              
                }
                else if (rebMainN[i].CBarMark == "c")
                {
                    txtMainN = value + " -" + rebMainN[i].Quantity + "-" + rebMainN[i].Diameter.ToString();
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtMainN, "string");
                    dic.Add("N3C", dicV);

                    string val = rebMainN[i].Length.ToString("0.000");
                    dicV = new Dictionary<string, string>();
                    dicV.Add(val, "string");
                    dic.Add("LENN3", dicV);
                }
            }


            List<RebarBase> rebN = RebarList.FindAll(t => (t.MBarMark == 4));
            string txtN = "";        
            for (int i = 0; i < rebN.Count; i++)
            {
                string value;
                if (rebN[i].SBarMark != 0)
                    value = rebN[i].MBarMark.ToString() + "." + rebN[i].SBarMark.ToString() + rebN[i].CBarMark;
                else
                    value = rebN[i].MBarMark.ToString() + rebN[i].CBarMark;
                if (rebN[i].CBarMark == "a")
                {
                    txtN = value + "  -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN4 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N4A", dicV);
                }
                else if (rebN[i].CBarMark == "b")
                {
                    txtN = value + " -" + rebN[i].Quantity + " -" + rebN[i].Diameter.ToString() + "@" + (spaceN4 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N4B", dicV);
                }
                else
                {
                    txtN = value + "  -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN4 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N4C", dicV);
                }
            }
            rebN = RebarList.FindAll(t => (t.MBarMark == 5));
            for (int i = 0; i < rebN.Count; i++)
            {
                string value;
                if (rebN[i].SBarMark != 0)
                    value = rebN[i].MBarMark.ToString() + "." + rebN[i].SBarMark.ToString() + rebN[i].CBarMark;
                else
                    value = rebN[i].MBarMark.ToString() + rebN[i].CBarMark;
                if (rebN[i].CBarMark == "a")
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN5 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N5A", dicV);
                }
                else if (rebN[i].CBarMark == "b")
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN5 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N5B", dicV);
                }
                else
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN5 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N5C", dicV);
                }
            }
            rebN = RebarList.FindAll(t => (t.MBarMark == 6));
            for (int i = 0; i < rebN.Count; i++)
            {
                string value;
                if (rebN[i].SBarMark != 0)
                    value = rebN[i].MBarMark.ToString() + "." + rebN[i].SBarMark.ToString() + rebN[i].CBarMark;
                else
                    value = rebN[i].MBarMark.ToString() + rebN[i].CBarMark;
                if (rebN[i].CBarMark == "a")
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN6 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N6A", dicV);
                }
                else if (rebN[i].CBarMark == "b")
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN6 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N6B", dicV);
                }
                else
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN6 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N6C", dicV);
                }
            }

            rebN = RebarList.FindAll(t => (t.MBarMark == 7));
            for (int i = 0; i < rebN.Count; i++)
            {
                string value;
                if (rebN[i].SBarMark != 0)
                    value = rebN[i].MBarMark.ToString() + "." + rebN[i].SBarMark.ToString() + rebN[i].CBarMark;
                else
                    value = rebN[i].MBarMark.ToString() + rebN[i].CBarMark;
                if (rebN[i].CBarMark == "a")
                {
                    txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";
                    dicV = new Dictionary<string, string>();
                    dicV.Add(txtN, "string");
                    dic.Add("N7A", dicV);
                }
                else
                {
                    if(rebN[i].CBarMark == "b")
                    {
                        txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";
                        dicV = new Dictionary<string, string>();
                        dicV.Add(txtN, "string");
                        dic.Add("N7B", dicV);
                    }
                    if ((rebN.Count == 2 && rebN[i].CBarMark == "b") || (rebN.Count == 3 && rebN[i].CBarMark == "c") || (rebN.Count == 4 && rebN[i].CBarMark == "d"))
                    {
                        txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";
                        dicV = new Dictionary<string, string>();
                        dicV.Add(txtN, "string");
                        dic.Add("N7D", dicV);
                    }
                    if (rebN.Count == 3 && rebN[i].CBarMark == "b")
                    {
                        txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";
                    
                        TextPloter.CreateRibMLeader(startPoint.Convert2D(43, 79.5-0.0291), startPoint.Convert2D(71.4, 74.6), txtN, ref ext,1,0.2);
                        //TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(80.6,94.2-0.6725), txtN,GeTools.DegreeToRadian(90));
                    }
                    else if (rebN.Count == 4)
                    {
                        txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";
                        if(rebN[i].CBarMark == "b")
                        {
                            TextPloter.CreateRibMLeader(startPoint.Convert2D(43, 79.5 - 0.0291+36.35), startPoint.Convert2D(71.4, 74.6+12), txtN, ref ext, 1, 0.2);
                        }
                        else if (rebN[i].CBarMark == "c")
                        {
                            TextPloter.CreateRibMLeader(startPoint.Convert2D(43, 79.5 - 0.0291), startPoint.Convert2D(71.4, 74.6), txtN, ref ext, 1, 0.2);
                        }
                    }

                    if (rebN.Count == 3 && rebN[i].CBarMark == "c")
                    {
                        txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";

                        TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(80.6, 94.2 - 0.6725), txtN, GeTools.DegreeToRadian(90));
                    }
                    else if (rebN.Count == 4)
                    {
                        txtN = value + " -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "(SR)";
                        if (rebN[i].CBarMark == "c")
                        {
                            TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(80.6, 94.2 - 0.6725), txtN, GeTools.DegreeToRadian(90));
                        }
                        else if (rebN[i].CBarMark == "d")
                        {
                            TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(80.6 + 3.7, 94.2 - 0.6725), txtN, GeTools.DegreeToRadian(90));
                        }
                    }
                }
            }
            txtN = N4.ToString() + "@" + (spaceN4 * 0.001).ToString("0.000");
            dicV = new Dictionary<string, string>();
            dicV.Add(txtN, "string");
            dic.Add("N4D", dicV);
            txtN = N5.ToString() + "@" + (spaceN5 * 0.001).ToString("0.000");
            dicV = new Dictionary<string, string>();
            dicV.Add(txtN, "string");
            dic.Add("N5D", dicV);
            txtN = N6.ToString() + "@" + (spaceN6 * 0.001).ToString("0.000");
            dicV = new Dictionary<string, string>();
            dicV.Add(txtN, "string");
            dic.Add("N6D", dicV);


            double LEN = Length;
            double LEN1 = Length - Cover * 0.001 * 2;
            double LEN2 = Length - Cover * 0.001 - 8 - 6.5;
            dicV = new Dictionary<string, string>();
            dicV.Add(LEN.ToString("0.000"), "string");
            dic.Add("LEN", dicV);
            dicV = new Dictionary<string, string>();
            dicV.Add(LEN1.ToString("0.000"), "string");
            dic.Add("LEN1", dicV);
            dicV = new Dictionary<string, string>();
            dicV.Add(LEN2.ToString("0.000"), "string");
            dic.Add("LEN2", dicV);

            dicV = new Dictionary<string, string>();
            dicV.Add((DiaPile*0.001).ToString("0.0"), "string");
            dic.Add("D", dicV);

            dicV = new Dictionary<string, string>();
            dicV.Add(ePCType.ToString().ToUpper(), "string");
            dic.Add("TYPE", dicV);

            double LD = DowelLen * 0.001;
            //double N1LD = 12- DowelLen*0.001-6.5- N2CAP;
            //double N2LD = 8+6.5-12+DowelLen * 0.001;
            //double N3LD = 12-N2CAP- N2LD-N3CAP;
            //double N3BLD = 12 - N3CAP*2;
            //List<RebarBase> rebN3 = RebarList.FindAll(t => (t.MBarMark == 3&&t.CBarMark=="c"));
            //if(rebN3.Count==0)
            //    rebN3 = RebarList.FindAll(t => (t.MBarMark == 3 && t.CBarMark == "b"));
            //double N3CLD = rebN3[0].Length - N3CAP;
            dicV = new Dictionary<string, string>();
            dicV.Add(LD.ToString("0.000"), "string");
            dic.Add("LD", dicV);
            //dicV = new Dictionary<string, string>();
            //dicV.Add(N1LD.ToString("0.000"), "string");
            //dic.Add("N1LD", dicV);
            //dicV = new Dictionary<string, string>();
            //dicV.Add(N2LD.ToString("0.000"), "string");
            //dic.Add("N2LD", dicV);
            //dicV = new Dictionary<string, string>();
            //dicV.Add(N3LD.ToString("0.000"), "string");
            //dic.Add("N3LD", dicV);
            //dicV = new Dictionary<string, string>();
            //dicV.Add(N3BLD.ToString("0.000"), "string");
            //dic.Add("N3BLD", dicV);
            //dicV = new Dictionary<string, string>();
            //dicV.Add(N3CLD.ToString("0.000"), "string");
            //dic.Add("N3CLD", dicV);

            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt.Convert3D(0, -5), scale, _blcName, _dwgPath, dic, null, ref ext);
        }


        public void DrawingPileStructure(Database db, ref Extents2d ext, Point3d startPoint, string _dwgPath, RebarCollection RebarList)
        {
            //Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            double scale = 1;
            Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicV = new Dictionary<string, string>();
            string _blcName = "DetailA";
            Point3d blockPt = startPoint;


            string strDia = "Φ" + ((DiaPile - 2 * Cover) * 0.001).ToString("0.000") + " (OD)";
            dic = new Dictionary<string, Dictionary<string, string>>();
            dicV = new Dictionary<string, string>();
            dicV.Add(strDia, "string");
            dic.Add("DIA", dicV);
            _blcName = "CoverBlock";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt.Convert3D(0, -5), scale, _blcName, _dwgPath, dic, null, ref ext);

            blockPt = startPoint.Convert3D(0, -50);
            _blcName = "CoverDetail";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt, scale, _blcName, _dwgPath, null, null, ref ext);

            blockPt = startPoint.Convert3D(75, 55);
            _blcName = "DetailA";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt, scale, _blcName, _dwgPath, null, null, ref ext);
            Point3d ptT = blockPt.Convert3D(32.62, 23.4);
            List<RebarBase> reb = RebarList.FindAll(t => t.MBarMark == 7);
            for (int i = 0; i < reb.Count; i++)
            {
                string value;
                if (reb[i].SBarMark != 0)
                    value = reb[i].MBarMark.ToString() + "." + reb[i].SBarMark.ToString() + reb[i].CBarMark;
                else
                    value = reb[i].MBarMark.ToString() + reb[i].CBarMark;
                string txt = value + "  -" + reb[i].Quantity + "-" + reb[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "SR";
                if (reb.Count == 2)
                {
                    TextPloter.PlotPileRebarText(db, ref ext, ptT.Convert3D(0, -3.6 * i), txt);
                }
                else
                {
                    TextPloter.PlotPileRebarText(db, ref ext, ptT.Convert3D(0, 3.6 - 3.6 * i), txt);
                }
                Point2d ptSection = startPoint.Convert2D(15, 100);
                if (reb.Count == 2)
                {
                    string str1 = "STIFFENER RING";
                    string str2 = "1:25@A3";
                    TextPloter.PrintScaleDoubleSideTextNew(db, ptSection.Convert2D(0, 12 + 2.4), 2 * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
                }
                else
                {
                    string str1 = "STIFFENER RING";
                    string str2 = "1:25@A3";
                    TextPloter.PrintScaleDoubleSideTextNew(db, ptSection.Convert2D(15, 12 + 2.4), 2 * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
                }
                if (reb[i].CBarMark == "a")
                    PlotSection(db, ptSection.Convert2D(0, 0), ref ext, PhiTop, txt);
                else if (reb[i].CBarMark == "b")
                    PlotSection(db, ptSection.Convert2D(0, -32), ref ext, PhiMitUp, txt);
                else if (reb[i].CBarMark == "c")
                    PlotSection(db, ptSection.Convert2D(30, 0), ref ext, PhiMitLo, txt, TextPloter.ePileTxtLocation.E_RIGHT_T);
                else if (reb[i].CBarMark == "d")
                    PlotSection(db, ptSection.Convert2D(30, -32), ref ext, PhiBot, txt);

            }
            //TextPloter.PlotText(db, ref ext, ptT, "7a  -12-DB",1);

            blockPt = startPoint.Convert3D(75, -12);
            _blcName = "DetailB";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt, scale, _blcName, _dwgPath, null, null, ref ext);

            blockPt = startPoint.Convert3D(75, -73);
            _blcName = "DetailC2Hook";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt, scale, _blcName, _dwgPath, null, null, ref ext);


            blockPt = startPoint.Convert3D(75-12.5, -73-10);
            _blcName = "DetailCN";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt, scale, _blcName, _dwgPath, null, null, ref ext);
        }

        public void DrawingNote(Database db, ref Extents2d ext, Point3d startPoint, string _dwgPath)
        {
            double scale = 1;
            string _blcName = "Note";
            Point3d blockPt = startPoint;


            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt.Convert3D(0, -5), scale, _blcName, _dwgPath, null, null, ref ext);

        }

        public static void PlotSection(Database db, Point2d startPoint, ref Extents2d ext, double dia, string N7 = "", TextPloter.ePileTxtLocation eL = TextPloter.ePileTxtLocation.E_RIGHT_B)
        {
            double radI = 10.7, radO = 11.7;
            string strDia = "Φ" + (dia * 0.001).ToString("0.000") + " (OD)";
            Arc arcCal = new Arc(startPoint.Convert3D(), radO, GeTools.DegreeToRadian(0), GeTools.DegreeToRadian(360));
            Line lineCal = new Line(startPoint.Convert3D(-radO, -radO), startPoint.Convert3D(radO, radO));
            Point3dCollection pts = new Point3dCollection();
            lineCal.IntersectWith((Entity)arcCal, Intersect.ExtendBoth, pts, IntPtr.Zero, IntPtr.Zero);
            PolylinePloter.AddCircle(startPoint, radO, ref ext, "细线");
            PolylinePloter.AddCircle(startPoint, radI, ref ext, "细线");
            PolylinePloter.CreateArc(db, ref ext, startPoint.Convert3D(-1.2982, -7.6714), 4.0022, 208, 246);
            PolylinePloter.CreateArc(db, ref ext, startPoint.Convert3D(1.2982, -7.6714), 4.0022, 294, 332);
            if (pts.Count > 1)
                DimPloter.DimAliByDimStyleName(db, ref ext, pts[0].Convert3D(), pts[1].Convert3D(), startPoint.Convert3D(0, 0), 1, strDia);
            DimPloter.DimRot(db, startPoint.Convert3D(-radO * 0.25), startPoint.Convert3D(radO * 0.25), startPoint.Convert3D(0, -radO - 3.5), ref ext, 0, 1, "0.300");
            switch (eL)
            {
                case TextPloter.ePileTxtLocation.E_RIGHT_B:
                    TextPloter.DrawPileLeadText(db, startPoint.Convert2D(radO * 0.25, radO * Math.Sin(294)), eL, radO * 0.5, N7, ref ext);
                    break;
                case TextPloter.ePileTxtLocation.E_RIGHT_T:
                    TextPloter.DrawPileLeadText(db, startPoint.Convert2D(radO), eL, radO * 0.5, N7, ref ext);
                    break;
                case TextPloter.ePileTxtLocation.E_LEFT_B:
                    TextPloter.DrawPileLeadText(db, startPoint.Convert2D(-radO * 0.25, radO * Math.Sin(294)), eL, radO * 0.5, N7, ref ext);
                    break;
                case TextPloter.ePileTxtLocation.E_LEFT_T:
                    TextPloter.DrawPileLeadText(db, startPoint.Convert2D(-radO), eL, radO * 0.5, N7, ref ext);
                    break;
            }
        }


        public void DrawSection(Database db, ref Extents2d ext, Point2d startPoint, RebarCollection RebarList)
        {
            double len = 65;
            double rad = 10;
            string str1 = " Ⅰ-Ⅰ ";
            string str2 = "1:25@A3";
            TextPloter.PrintScaleDoubleSideTextNew(db, startPoint.Convert2D(0, 0), 2 * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
            DrawingSection(db, ref ext, startPoint.Convert2D(0, -2.6 - rad - 10), RebarList, 1, rad);

            str1 = " Ⅱ-Ⅱ ";
            str2 = "1:25@A3";
            TextPloter.PrintScaleDoubleSideTextNew(db, startPoint.Convert2D(len, 0), 2 * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
            DrawingSection(db, ref ext, startPoint.Convert2D(len, -2.6 - rad - 10), RebarList, 2, rad);

            str1 = " Ⅲ-Ⅲ ";
            str2 = "1:25@A3";
            TextPloter.PrintScaleDoubleSideTextNew(db, startPoint.Convert2D(len * 2, 0), 2 * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
            DrawingSection(db, ref ext, startPoint.Convert2D(len * 2, -2.6 - rad - 10), RebarList, 3, rad);
        }

        public void DrawingSection(Database db, ref Extents2d ext, Point2d startPoint, RebarCollection RebarList, int divNum = 1, double rad = 10)
        {

            PolylinePloter.AddCircle(startPoint, rad, ref ext, "细线");
            PolylinePloter.AddCircle(startPoint, rad + 0.8 * 2, ref ext, "细线");
            Circle circle = new Circle(startPoint.Convert3D(rad + 0.8), Vector3d.ZAxis, 0.8) { ColorIndex = 6 };
            List<int> hatchL = new List<int>();
            List<int> hatchNL = new List<int>();
            List<int> hatchV = new List<int>();

            List<int> hatchNV = new List<int>();
            List<Entity> hEnt;
            List<Entity> nhEnt;
            if (divNum == 1)
            {

                if (numN1 == numN2)
                {
                    for (int i = 0; i < numN1; i++)
                    {
                        hatchL.Add(i);
                    }
                }
                else
                {
                    int countN = numN1 - numN2;
                    int div = numN1 / countN;
                    double div1 = Math.Round(numN1 / Math.Round((double)countN, 1), 1);
                    double cap = Math.Round(numN1 / Math.Round((double)countN, 1) - div, 1);
                    double stDiv = 0;
                    for (int i = 0; i < numN1; i++)
                    {

                        if (cap != 0)
                        {
                            int num = i + 1;

                            if (cap < 0.5)
                                cap = 0.5;
                            if (num - (hatchNL.Count + 1) * div1 >= -cap&&num - (hatchNL.Count + 1) * div1 <= cap)
                            {
                                hatchNL.Add(i);
                            }
                            else
                            {
                                hatchL.Add(i);
                            }

                        }
                        else
                        {
                            if (i % div != 1)
                            {
                                hatchL.Add(i);
                            }
                            else
                            {
                                hatchNL.Add(i);
                            }
                        }
                    }
                }
                PileRebarDrawing.ArrayPolarEntity(circle, numN1, 360, startPoint.Convert3D(), hatchL, hatchNV, out hEnt, out nhEnt);
            }
            else if (divNum == 2)
            {
                hatchNV = new List<int>();
                hatchV = new List<int>();
                hatchL = new List<int>();
                hatchNL = new List<int>();
                if (numN1 == numN2)
                {
                    hatchNV = new List<int>();
                    for (int i = 0; i < numN1; i++)
                    {
                        hatchV.Add(i);
                    }
                }
                else
                {
                    int countN = numN1 - numN2;
                    int div = numN1 / countN;
                    double div1 = Math.Round(numN1 / Math.Round((double)countN, 1), 1);
                    double cap = Math.Round(numN1 / Math.Round((double)countN, 1) - div, 1);
                    double stDiv = 0;
                    for (int i = 0; i < numN1; i++)
                    {
                        
                        if (cap != 0)
                        {
                            int num = i + 1;
                           
                            if (cap < 0.5)
                                cap = 0.5;
                            if (num - (hatchNV.Count + 1) * div1 >= -cap && num - (hatchNV.Count + 1) * div1 <= cap)
                            {
                                hatchNV.Add(i);
                            }
                            else
                            {
                                hatchV.Add(i);
                            }

                        }
                        else
                        {
                            if (i % div != 1)
                            {
                                hatchV.Add(i);
                            }
                            else
                            {
                                hatchNV.Add(i);
                            }
                        }
                    }

                }
                if (numN2 == numN3)
                {
                    for (int i = 0; i < numN1; i++)
                    {
                        if (hatchV.Contains(i))
                        {
                            hatchL.Add(i);
                        }
                    }
                }
                else
                {
                    int countN = numN2 - numN3;
                    int div = numN2 / countN;
                    double div1 = Math.Round(numN2 / Math.Round((double)countN, 1), 1);
                    double cap = Math.Round(numN2 / Math.Round((double)countN, 1) - div, 1);
                    int num = 0;
                    double stDiv = 0;
                    List<int> NN = new List<int>();
                    for (int i = 0; i < numN1; i++)
                    {
                        if (hatchV.Contains(i))
                        {
                            num++;

                            if (cap != 0)
                            {                                
                                if (cap < 0.5)
                                    cap = 0.5;
                                if (num - (hatchNL.Count + 1) * div1 >= -cap && num - (hatchNL.Count + 1) * div1 <= cap)
                                {
                                    hatchNL.Add(i);
                                }
                                else
                                {
                                    hatchL.Add(i);
                                }
                            }
                            else
                            {
                                if ((num-1) % div != 1)
                                {
                                    hatchL.Add(i);
                                }
                                else
                                {
                                    hatchNL.Add(i);
                                }
                            }
                        }
                    }
                    
                }
                PileRebarDrawing.ArrayPolarEntity(circle, numN1, 360, startPoint.Convert3D(), hatchL, hatchNV, out hEnt, out nhEnt);

            }
            else
            {
                #region 截面3
                hatchNV = new List<int>();
                hatchV = new List<int>();
                hatchL = new List<int>();
                hatchNL = new List<int>();
                if (numN1 == numN2)
                {
                    hatchNV = new List<int>();
                    for (int i = 0; i < numN1; i++)
                    {
                        hatchV.Add(i);
                    }
                }
                else
                {
                    int countN = numN1 - numN2;
                    int div = numN1 / countN;
                    double div1 = Math.Round(numN1 / Math.Round((double)countN, 1), 1);
                    double cap = Math.Round(numN1 / Math.Round((double)countN, 1) - div, 1);
                    double stDiv = 0;
                    for (int i = 0; i < numN1; i++)
                    {
                        if (cap != 0)
                        {
                            int num = i + 1;
                            if (cap < 0.5)
                                cap = 0.5;
                            if (num - (hatchNV.Count + 1) * div1 >= -cap && num - (hatchNV.Count + 1) * div1 <= cap)
                            {
                                hatchNV.Add(i);
                            }
                            else
                            {
                                hatchV.Add(i);
                            }
                           
                        }
                        else
                        {
                            if (i % div != 1)
                            {
                                hatchV.Add(i);
                            }
                            else
                            {
                                hatchNV.Add(i);
                            }
                        }
                    }
                }
                if (numN2 == numN3)
                {
                    for (int i = 0; i < numN1; i++)
                    {
                        if (hatchV.Contains(i))
                        {
                            hatchL.Add(i);
                        }
                    }
                }
                else
                {
                    int countN = numN2 - numN3;
                    int div = numN2 / countN;
                    double div1 = Math.Round(numN2 / Math.Round((double)countN, 1), 1);
                    double cap = Math.Round(numN2 / Math.Round((double)countN, 1) - div, 1);
                    int num = 0;      
                    for (int i = 0; i < numN1; i++)
                    {
                        if (hatchV.Contains(i))
                        {
                            num++;

                            if (cap != 0)
                            {
                                if (cap < 0.5)
                                    cap = 0.5;
                                if (num - (hatchNL.Count + 1) * div1 >= -cap && num - (hatchNL.Count + 1) * div1 <= cap)
                                {
                                    hatchNV.Add(i);
                                    hatchNL.Add(i);
                                }
                                else
                                {
                                    hatchL.Add(i);
                                }
                                
                            }
                            else
                            {
                                if ((num-1) % div != 1)
                                {
                                    hatchL.Add(i);
                                }
                                else
                                {
                                    hatchNV.Add(i);
                                }
                            }
                        }
                    }
                }
                PileRebarDrawing.ArrayPolarEntity(circle, numN1, 360, startPoint.Convert3D(), hatchL, hatchNV, out hEnt, out nhEnt);

                #endregion 
            }
            double h = 4;
            if (hEnt.Count > 0)
            {
                Circle cDima;
                //if (hEnt.Count > 2)
                //    cDima = (Circle)hEnt[2];
                //else
                cDima = (Circle)hEnt[1];
                if (cDima.Center.Y > startPoint.Y)
                {
                    if (cDima.Center.Y - startPoint.Y < rad)
                        h = h * 1.4;
                }
                else
                {
                    if (startPoint.Y - cDima.Center.Y > rad * 0.5)
                        h = h * 0.45;
                }
                List<RebarBase> reb = RebarList.FindAll(t => (t.MBarMark == divNum && t.CBarMark == "a") || (t.MBarMark == divNum && t.CBarMark == ""));
                if (divNum == 3)
                    reb = RebarList.FindAll(t => (t.MBarMark == divNum)).OrderBy(t => t.CBarMark).ToList();
                string txt = "";

                for (int i = 0; i < reb.Count; i++)
                {
                    string value;
                    if (reb[i].SBarMark != 0)
                        value = reb[i].MBarMark.ToString() + "." + reb[i].SBarMark.ToString() + reb[i].CBarMark;
                    else
                        value = reb[i].MBarMark.ToString() + reb[i].CBarMark;
                    if (reb[i].CBarMark == "")
                        txt = " " + value + "  -" + reb[i].Quantity + "-" + reb[i].Diameter.ToString();
                    else
                        txt = value + "  -" + reb[i].Quantity + "-" + reb[i].Diameter.ToString();
                    if (divNum == 3)
                    {
                        if (i > 0)
                        {
                            if (cDima.Center.Y > startPoint.Y)
                                TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D((rad + 0.8 * 2 + 3) + 2, (rad + 0.8 * 2 + 3) + 0.2 + 1.8 - 2 - 3.6 * i), txt);
                            else
                                TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D((rad + 0.8 * 2 + 3) + 2, -(rad + 0.8 * 2) + 0.2 + 1.8 - 3.6 * i), txt);
                        }
                        else
                        {
                            if (cDima.Center.Y > startPoint.Y)
                            {
                                TextPloter.CreateRibMLeader(cDima.Center.Convert2D(), startPoint.Convert2D((rad + 0.8 * 2 + 3), (rad + 0.8 * 2 + 3) + 0.2 - 2), txt, ref ext);
                            }
                            else
                            {
                                TextPloter.CreateRibMLeader(cDima.Center.Convert2D(), startPoint.Convert2D(rad + 0.8 * 2 + 3, -(rad + 0.8 * 2)), txt, ref ext);
                            }
                        }
                    }
                    else
                        break;
                }
                if (divNum != 3)
                {
                    if (cDima.Center.Y > startPoint.Y)
                    {
                        TextPloter.CreateRibMLeader(cDima.Center.Convert2D(), startPoint.Convert2D((rad + 0.8 * 2 + 3), (rad + 0.8 * 2 + 3) + 0.2-2), txt, ref ext);
                    }
                    else
                    {
                        TextPloter.CreateRibMLeader(cDima.Center.Convert2D(), startPoint.Convert2D(rad + 0.8 * 2 + 3, -(rad + 0.8 * 2)), txt, ref ext);
                    }
                }
            }
            if (nhEnt.Count > 0)
            {
                Circle cDimb = (Circle)nhEnt[nhEnt.Count - 1];
                if (cDimb.Center.Y > startPoint.Y)
                {
                    if (cDimb.Center.Y - startPoint.Y < rad)
                        h = h * 1.4;
                }
                else
                {
                    if (startPoint.Y - cDimb.Center.Y > rad * 0.5)
                        h = h * 0.45;
                }
                List<RebarBase> reb = RebarList.FindAll(t => (t.MBarMark == divNum && t.CBarMark == "b") || (t.MBarMark == divNum && t.CBarMark == ""));
                string txt = "";
                for (int i = 0; i < reb.Count; i++)
                {
                    string value;
                    if (reb[i].SBarMark != 0)
                        value = reb[i].MBarMark.ToString() + "." + reb[i].SBarMark.ToString() + reb[i].CBarMark;
                    else
                        value = reb[i].MBarMark.ToString() + reb[i].CBarMark;
                    txt = value + "  -" + reb[i].Quantity + "-" + reb[i].Diameter.ToString();
                    break;
                }
                //TextPloter.CreateRibMLeader(cDima.Center.Convert2D(), cDima.Center.Convert2D(h * 0.6, h), txt, ref ext);

                if (cDimb.Center.Y > startPoint.Y)
                {

                    TextPloter.CreateRibMLeader(cDimb.Center.Convert2D(), startPoint.Convert2D((rad + 0.8 * 2 + 3), (rad + 0.8 * 2 + 3) + 0.2+1.6), txt, ref ext);
                }
                else
                {

                    TextPloter.CreateRibMLeader(cDimb.Center.Convert2D(), startPoint.Convert2D(rad + 0.8 * 2 + 3, -(rad + 0.8 * 2+3)), txt, ref ext);
                }
            }

            List<RebarBase> rebN = RebarList.FindAll(t => (t.MBarMark == (divNum + 3)));
            string txtN = "";
            PolylinePloter.AddLine(db, ref ext, startPoint.Convert3D(rad + 0.8 * 2), startPoint.Convert3D(rad + 0.8 * 2 + 3 + 1), "细线");
            for (int i = 0; i < rebN.Count; i++)
            {
                string value;
                if (rebN[i].SBarMark != 0)
                    value = rebN[i].MBarMark.ToString() + "." + rebN[i].SBarMark.ToString() + rebN[i].CBarMark;
                else
                    value = rebN[i].MBarMark.ToString() + rebN[i].CBarMark;
                if (divNum == 1)
                    txtN = value + "  -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN4 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                else if (divNum == 2)
                    txtN = value + "  -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN5 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                else
                    txtN = value + "  -" + rebN[i].Quantity + "-" + rebN[i].Diameter.ToString() + "@" + (spaceN6 * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SS)";
                TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D(rad + 0.8 * 2 + 3 + 1, 3.6 - 3.6 * i), txtN);

            }

            List<RebarBase> rebN7 = RebarList.FindAll(t => (t.MBarMark == 7));
            if (divNum == 1)
            {
                rebN7 = RebarList.FindAll(t => (t.MBarMark == 7 && t.CBarMark == "a"));
                string txtN7 = "";
                //PolylinePloter.AddLine(db, ref ext, startPoint.Convert3D(-rad*Math.Cos(45), -rad * Math.Sin(45)), startPoint.Convert3D(rad + 0.8 * 2 + 3 + 1), "细线");
                Point3d ptN7 = startPoint.Convert3D(-rad * Math.Cos(45), -rad * Math.Sin(45));
                for (int i = 0; i < rebN7.Count; i++)
                {
                    string value;
                    if (rebN7[i].SBarMark != 0)
                        value = rebN7[i].MBarMark.ToString() + "." + rebN7[i].SBarMark.ToString() + rebN7[i].CBarMark;
                    else
                        value = rebN7[i].MBarMark.ToString() + rebN7[i].CBarMark;

                    txtN7 = value + "  -" + rebN7[i].Quantity + "-" + rebN7[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SR)";
                    TextPloter.CreateRibMLeader(ptN7.Convert2D(), startPoint.Convert2D(-(rad + 0.8 * 2 + 3), -(rad + 0.8 * 2) + 0.1), txtN7, ref ext);
                    break;
                }
            }
            else if (divNum == 2)
            {
                rebN7 = RebarList.FindAll(t => (t.MBarMark == 7 && t.CBarMark == "b"));
                string txtN7 = "";
                //PolylinePloter.AddLine(db, ref ext, startPoint.Convert3D(-rad*Math.Cos(45), -rad * Math.Sin(45)), startPoint.Convert3D(rad + 0.8 * 2 + 3 + 1), "细线");
                Point3d ptN7 = startPoint.Convert3D(-rad * Math.Cos(45), -rad * Math.Sin(45));
                for (int i = 0; i < rebN7.Count; i++)
                {
                    string value;
                    if (rebN7[i].SBarMark != 0)
                        value = rebN7[i].MBarMark.ToString() + "." + rebN7[i].SBarMark.ToString() + rebN7[i].CBarMark;
                    else
                        value = rebN7[i].MBarMark.ToString() + rebN7[i].CBarMark;

                    txtN7 = value + "  -" + rebN7[i].Quantity + "-" + rebN7[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SR)";
                    TextPloter.CreateRibMLeader(ptN7.Convert2D(), startPoint.Convert2D(-(rad + 0.8 * 2 + 3), -(rad + 0.8 * 2) + 2), txtN7, ref ext);
                    break;
                }

            }
            else
            {
                if (rebN7.Count > 2)
                    rebN7 = RebarList.FindAll(t => (t.MBarMark == 7 && (t.CBarMark == "c") || (t.CBarMark == "d")));
                else
                    rebN7 = RebarList.FindAll(t => (t.MBarMark == 7 && t.CBarMark == "b"));
                string txtN7 = "";
                //PolylinePloter.AddLine(db, ref ext, startPoint.Convert3D(-rad*Math.Cos(45), -rad * Math.Sin(45)), startPoint.Convert3D(rad + 0.8 * 2 + 3 + 1), "细线");
                Point3d ptN7 = startPoint.Convert3D(rad * Math.Cos(45), -rad * Math.Sin(45));
                if (rebN7.Count > 2)
                {
                    for (int i = 0; i < rebN7.Count; i++)
                    {
                        string value;
                        if (rebN7[i].SBarMark != 0)
                            value = rebN7[i].MBarMark.ToString() + "." + rebN7[i].SBarMark.ToString() + rebN7[i].CBarMark;
                        else
                            value = rebN7[i].MBarMark.ToString() + rebN7[i].CBarMark;

                        txtN7 = value + "  -" + rebN7[i].Quantity + "-" + rebN7[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SR)";
                        TextPloter.CreateRibMLeader(ptN7.Convert2D(), startPoint.Convert2D((rad + 0.8 * 2 + 3), -(rad + 0.8 * 2)), txtN7, ref ext);
                    }
                }
                else
                {
                    for (int i = 0; i < rebN7.Count; i++)
                    {
                        string value;
                        if (rebN7[i].SBarMark != 0)
                            value = rebN7[i].MBarMark.ToString() + "." + rebN7[i].SBarMark.ToString() + rebN7[i].CBarMark;
                        else
                            value = rebN7[i].MBarMark.ToString() + rebN7[i].CBarMark;

                        txtN7 = value + "  -" + rebN7[i].Quantity + "-" + rebN7[i].Diameter.ToString() + "@" + (ringSpace * 0.001).ToString("0.000") + "×" + rebN[i].Length.ToString("0.000") + "(SR)";
                        if (i == 0)
                            TextPloter.CreateRibMLeader(ptN7.Convert2D(), startPoint.Convert2D((rad + 0.8 * 2 + 3), -(rad + 0.8 * 2)), txtN7, ref ext);
                        else
                        {
                            TextPloter.PlotPileRebarText(db, ref ext, startPoint.Convert3D((rad + 0.8 * 2 + 3) + 2, -(rad + 0.8 * 2) + 1.8 - 3.6 * i), txtN7);
                        }
                    }
                }

            }
            PolylinePloter.AddCircle(startPoint, rad + 0.8 * 2 + 3, ref ext, "细线");

            DimPloter.DimRot(db, startPoint.Convert3D(-(rad + 0.8 * 2 + 3)), startPoint.Convert3D(rad + 0.8 * 2 + 4.5), startPoint.Convert3D(0, rad + 0.8 * 2 + 3 + 4.5), ref ext, 0, 1, (DiaPile * 0.001).ToString("0.000"));
            DimPloter.DimRot(db, startPoint.Convert3D(-(rad + 0.8 * 2 + 3)), startPoint.Convert3D(-(rad + 0.8 * 2 + 3) + 3), startPoint.Convert3D(0, -(rad + 0.8 * 2 + 3) - 3), ref ext, 0, 1, "Net " + (Cover * 0.001).ToString("0.000"));
            DimPloter.DimRot(db, startPoint.Convert3D((rad + 0.8 * 2 + 3)), startPoint.Convert3D((rad + 0.8 * 2 + 3) - 3), startPoint.Convert3D(0, -(rad + 0.8 * 2 + 3) - 3), ref ext, 0, 1, "Net " + (Cover * 0.001).ToString("0.000"));

        }
        #endregion


        #region  UBOLT
        public void DrawingPileUbolt(Database db, Point3d startPoint, string _dwgPath, int pageNo = 0, int divNo = 0)
        {

            #region 绘制出图
            Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            DrawingPileUBolt(db, ref ext, startPoint.Convert3D(), _dwgPath);
            #endregion

            Common.CreateLayoutNew(db, "桩基钢筋", ext, 1, 1, pageNo, divNo, false);
        }

        public void DrawingPileUBolt(Database db, ref Extents2d ext, Point3d startPoint, string _dwgPath)
        {
            //Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            double scale = 1;
            Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicV = new Dictionary<string, string>();
            string _blcName = "UBOLT";
            Point3d blockPt = startPoint;

            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(blockPt.Convert3D(0, -5), scale, _blcName, _dwgPath, dic, null, ref ext);
        }
        #endregion
    }
}
